
//
// 121213 - AH - Created.
//

package org.japril.jutil.logging;

/**
 * <p>
 *   {@link LogFormater} that is used where none is specified by client, produce
 *   plain text.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public class DefaultLogFormater implements LogFormater
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public DefaultLogFormater(){}
  
  /**
   * <p>
   *   For compiling log messages in-
   * </p>
   */
  protected final StringBuilder m_sb=new StringBuilder();
  
  // Specified in LogFormater.
  public String format(Class<?> clazz, String method, String msg)
  {
    if (clazz==null && method==null) return msg;
    
    StringBuilder sb=m_sb;
    
    sb.setLength(0);
    if (clazz!=null) sb.append(clazz.getSimpleName());
    if (method!=null) 
    {
      if (sb.length()>0) sb.append(" : ");
      sb.append(method);
    }
    if (msg!=null)
    {
      if (sb.length()>0) sb.append(" : ");
      sb.append(msg);
    }
    return sb.toString();
  }
  
}
